<?php

namespace app\admin\controller;

use app\admin\service\MediaAssetService;
use app\common\Common;
use app\common\Error;
use app\model\Videos;
use app\Request;

class ThirdVideo extends Base
{
    public $service;

    public function __construct(MediaAssetService $service)
    {
        parent::__construct();
        $this->service = $service;
    }

    public function index()
    {
        return view();
    }

    //加入媒资管理列表
    public function add(Request $request)
    {
        if (!$request->isPost()){
            return Common::fail('错误的请求', 404);
        }

        $params = $request->param();
        if (empty($params['video_id']) || empty($params['type'])) {
            return Common::fail('参数错误', 404);
        }

        $result = $this->service->addThirdPartyVideo($params);
        if ($result) {
            count($result) > 1 ? [$msg, $code] = $result : $msg = $result[0];
            $code = $code ?? Error::FAIL_CODE;
            return Common::fail($msg, $code);
        }

        return Common::success();
    }

    //平台媒资列表
    public function list(Request $request)
    {
        $params = $request->param();
        $type = $params['type'] ?? 2;
        $data = [];
        switch ($type) {
            case 2: //抖音
                $data = $this->service->dyList($params);
                break;
            case 1: //微信
                $data = $this->service->wxList($params);
                break;
            default:
                break;
        }

        return Common::success($data);
    }

    public function detail(Request $request)
    {
        $params = $request->param();
        if (empty($params['id'])) {
            return Common::fail('参数错误', 404);
        }
        $data = $this->service->thirdVideoDetail($params['id']);
        return Common::success($data);
    }

    public function synchronization(){
        return view();
    }

    public function episodes()
    {
        return view();
    }

    public function authorize()
    {
        return view();
    }

    public function wx_authorize(){
        return view();
    }

    public function wx_episodes(){
        return view();
    }

    //查看列表
    public function view(Request $request)
    {
        $params = $request->param();
        if (empty($params['id'])) {
            return Common::fail('参数错误', 404);
        }

        $data = $this->service->viewList($params);

        return Common::success($data);
    }

    public function videoSelect(Request $request)
    {
        $params = $request->param();
        $data = $this->service->getVideoSelectList($params);

        return Common::success($data);
    }

}